Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/schema: Default hashing function for sets #3018

Merged
merged 1 commit into from
Oct 5, 2015
Merged

helper/schema: Default hashing function for sets #3018

merged 1 commit into from
Oct 5, 2015

Conversation

apparentlymart
Copy link
Contributor

A common issue with new resource implementations is not considering parts of a complex structure that's used inside a set, which causes quirky behavior.

The schema helper has enough information to provide a default reasonable implementation of a set function that includes all non-computed attributes in a deterministic way. Here we implement such a function and use it when no explicit hashing function is provided.

In order to achieve this we encapsulate the construction of the zero value for a schema in a new method schema.ZeroValue, which allows us to put the fallback logic to the new default function in a single spot. It is no longer valid to use &Set{F: schema.Set} and all uses of that construct should be replaced with schema.ZeroValue().(*Set) .

This was originally discussed in the feedback on #2336.

@apparentlymart
Copy link
Contributor Author

The change in #2162 is waiting for this to land to complete the support for specifying EBS volumes on Opsworks Layers.

@apparentlymart
Copy link
Contributor Author

The change in #3124 is waiting for this to land since it has a lot of Set attributes of various types and it would be very tedious to implement hashing for all of them.

A common issue with new resource implementations is not considering parts
of a complex structure that's used inside a set, which causes quirky
behavior.

The schema helper has enough information to provide a default reasonable
implementation of a set function that includes all non-computed attributes
in a deterministic way. Here we implement such a function and use it
when no explicit hashing function is provided.

In order to achieve this we encapsulate the construction of the zero
value for a schema in a new method schema.ZeroValue, which allows us to
put the fallback logic to the new default function in a single spot.
It is no longer valid to use &Set{F: schema.Set} and all uses of that
construct should be replaced with schema.ZeroValue().(*Set) .
@phinze
Copy link
Contributor

phinze commented Oct 5, 2015

This looks great, @apparentlymart. Merging!

phinze added a commit that referenced this pull request Oct 5, 2015
helper/schema: Default hashing function for sets
@phinze phinze merged commit 085dde5 into hashicorp:master Oct 5, 2015
@ghost
Copy link

ghost commented Apr 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants